<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script src="../vue.js"></script>
<script src="../vue-router.js"></script>

<body>
  <div id="app">
    <router-link to="/login" tag="span">前往login页面登录</router-link>
    <!-- router-view 页面或者组件的占位符 作用：显示页面-->
    <router-view> </router-view>
  </div>


  <script>
    // 创建登录组件
    var login = {
      template: "<h1> 登录组件 </h1>"
    }

    // 创建路由对象
    var routerObj = new VueRouter({
      mode: "history",
      // 配置路由的相关匹配规则
      routes: [{
        path: "/login",
        component: login
      }]
    })

    var vm = new Vue({
      el: "#app",
      // 讲路由规则对象注册到vm实例对象上
      router: routerObj,
    })
  </script>
</body>

</html>